// 认证相关API - 纯前端模拟数据

// 模拟用户数据
const mockUsers = [
  {
    id: 1,
    username: 'zhangsan',
    password: 'password123',
    name: '张三',
    role: '主唱',
    accountRole: 'user',
    accountStatus: 'active',
    avatar: 'https://joeschmoe.io/api/v1/1',
    email: 'zhangsan@example.com',
  },
  {
    id: 2,
    username: 'lisi',
    password: 'password123',
    name: '李四',
    role: '吉他手',
    accountRole: 'admin',
    accountStatus: 'active',
    avatar: 'https://joeschmoe.io/api/v1/2',
    email: 'lisi@example.com',
  },
  {
    id: 3,
    username: 'wangwu',
    password: 'password123',
    name: '王五',
    role: '贝斯手',
    accountRole: 'user',
    accountStatus: 'inactive',
    avatar: 'https://joeschmoe.io/api/v1/3',
    email: 'wangwu@example.com',
  },
];

// 模拟API响应
const mockApiResponse = (data, delay = 500) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({ data });
    }, delay);
  });
};

// 登录API
export const login = async (data) => {
  const { username, password } = data;
  
  const user = mockUsers.find(u => 
    u.username === username && 
    u.password === password && 
    u.accountStatus === 'active'
  );
  
  if (user) {
    return mockApiResponse({
      success: true,
      user: {
        id: user.id,
        username: user.username,
        name: user.name,
        role: user.role,
        accountRole: user.accountRole,
        avatar: user.avatar,
        email: user.email,
      },
      token: 'mock-token-' + Date.now(),
      message: '登录成功'
    });
  } else {
    return mockApiResponse({
      success: false,
      message: '用户名或密码错误'
    });
  }
};

// 登出API
export const logout = async () => {
  return mockApiResponse({
    success: true,
    message: '登出成功'
  });
};

// 获取用户信息API
export const getProfile = async () => {
  return mockApiResponse({
    success: true,
    user: {
      id: 1,
      username: 'zhangsan',
      name: '张三',
      role: '主唱',
      accountRole: 'user',
      avatar: 'https://joeschmoe.io/api/v1/1',
      email: 'zhangsan@example.com',
    }
  });
};

// 更新用户信息API
export const updateProfile = async (data) => {
  return mockApiResponse({
    success: true,
    user: data,
    message: '更新成功'
  });
};

// 刷新token API
export const refreshToken = async (refreshToken) => {
  return mockApiResponse({
    success: true,
    token: 'new-mock-token-' + Date.now(),
    message: 'Token刷新成功'
  });
}; 